package org.sao.security.demo.controller;

import java.util.HashMap;
import java.util.Map;

import org.sao.security.demo.exception.ZyException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ControllerExceptionHandler {
	
	
	@ExceptionHandler(ZyException.class)
	@ResponseBody
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	public Map<String,Object> handlerZyException (ZyException ex){
		 Map<String,Object> result =new HashMap<String,Object>();
		 result.put("status","0");
		 result.put("id", ex.getId());
		 result.put("message", ex.getMessage());
		 return result;
		
	}
	
	//@ExceptionHandler(Exception.class)
	//@ResponseBody
	public Map<String,Object> handlerException(Exception ex){
		 Map<String,Object> result =new HashMap<String,Object>();
		 result.put("status","0");
		 result.put("message", ex.getMessage()+ex.getLocalizedMessage());
		 return result;
		
	}
	

}
